<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://www.layuicdn.com/layui-v2.5.5/layui.js"></script>
    <title>网页测试推送版</title>

</head>
<body>
<form method="post" enctype="multipart/form-data">
    <label style="vertical-align: top;">推送方式：</label>
    <select  name="is_async" >
        <option value="1">异步</option>
        <option value="0">同步(数量限制</option>
    </select><br>
    <label style="vertical-align: top;">请选择包：</label>
    <select  attr="condition" data-live-search="true" name="package_id" >
    <?php foreach($packageList as $package){ ?>
        <option value="<?=$package['id']?>"><?=$package['id']?>[<?=$package['name']?>][<?=$package['appname']?>]</option>
    <?php } ?>
    </select><br>
    udid：<input type="text"  attr="condition" name="udid" value=""  style="width: 800px;"/><input type="file" name="udid_file" />暂只支持csv,最大文件大小250M<br>
    token：<input type="text"  attr="condition" name="token" value=""  style="width: 800px;" /><input type="file" name="token_file" />暂只支持csv,最大文件大小250M<br>
    角色id/角色名称：<input type="text"  attr="condition" name="role_name" value=""  style="width: 300px;"/><br>
    区服id/区服名：<input type="text"  attr="condition" name="server_name" value=""  style="width: 300px;" /><a   href="javascript:void(0)" id="token">搜索token(最大搜索10个</a><br>

    <a href="javascript:void(0)" class="download" field="all">下载udid和token</a>
    <a href="javascript:void(0)" class="download" field="udid">下载udid</a>
    <a href="javascript:void(0)" class="download" field="token">下载token</a>
    <!--<a target="_blank"  href="download_token">打开下载页面</a>-->

    <fieldset>
    <legend>通知基本消息</legend>
    标题：<input type="text" name="notification[title]" value="标题" />
    主体内容：<input type="text" name="notification[body]" value="内容"  /> 消息类型<input type="input" name="message_type" value="0"/>
    </fieldset>

    <fieldset>
        <legend>其他通知设置</legend>
        声音sound：<input type="text" name="custom_data[sound]" value="default" />
        图片地址image：<input type="text" style="width: 600px" name="custom_data[image]" value="https://ali-tapplus-oss-01.oss-cn-guangzhou.aliyuncs.com/admin/uploads/avatar/6281fb4539d64.png" />
        颜色(andrord)color：<input type="text" name="custom_data[color]" value="" placeholder="格式:#cddf15"/>
        徽章badge<input type="text" name="custom_data[badge]" value="1"/>
        子标题(ios)setSubtitle<input type="text" name="custom_data[setSubtitle]" value="副标题"/>
    </fieldset>

    <fieldset>
        <legend>透传消息</legend>
        <textarea rows="10" style="width: 40%" name="custom_data[data]"  placeholder="json格式"></textarea>
    </fieldset>

    <fieldset>
        <legend>android 指定设置</legend>
        <textarea rows="10" style="width: 40%" name="custom_data[android_option]">{"ttl":"60s"}</textarea>
    </fieldset>

    <fieldset>
        <legend>ios 指定设置</legend>
        <textarea rows="10" style="width: 40%" name="custom_data[ios_option]"></textarea>
    </fieldset>

    <fieldset>
        <legend>android 特定透传</legend>
        <textarea rows="10" style="width: 40%" name="custom_data[android_notification]">{"channel_id":"23","icon":"stock_ticker_update"}</textarea>
    </fieldset>

    <fieldset>
        <legend>ios 特定透传</legend>
        <textarea rows="10" style="width: 40%" name="custom_data[ios_notification]">{"mutable-content":1,"category":"realtime"}</textarea>
    </fieldset>
    <button type="submit">提交</button>
</form>
</body>
</html>

<script>
    $('.download').on('click',function(obj){
        var param = ['type=1'];
        let field = $(this).attr('field');
        if(field=='all'){
            param.push('field[]=udid');
            param.push('field[]=token');
        }else{
            param.push('field[]='+field);
        }

        let status = false;
        $("[attr='condition']").each(function(i){
            let name = $(this).attr('name');
            let value = $(this).val();
            param.push(name+'='+value);
            if(name=='role_name' || name=='server_name'){
                if(value) status = true;
            }
        });
        console.log(status);
        if(!status){
            //alert('必须选择(角色id/角色名称)或(区服id/区服名)才能下载');return;
        }
        var tempwindow = window.open('_blank');
        tempwindow.location = '/download_token?'+ param.join('&');
    });

    $('#token').on('click',function(obj){
        var param2 = {search:1};
        $("[attr='condition']").each(function(i){
            let name = $(this).attr('name');
            let value = $(this).val();
            param2[name] = value;
        });
        console.log(param2);
        $.post('/push_html',param2,function (data) {
            console.log(data.length);
            if(data.length>1){
                confirm('当前有'+data.length+'个'+data.join("-----------\r\n"));return;
                return;
            }
            if(data){
                $('input[name="token"]').val(data);
            }
        },'json')
    });
</script>
